package top.ucat.x.system.controller.management;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.ucat.box.cloud.common.result.Result;
import top.ucat.box.cloud.common.result.SystemResult;
import top.ucat.box.starter.mybatis.plus.base.controller.AbstractBaseController;
import top.ucat.box.starter.oauth.common.annotation.AutoPermission;
import top.ucat.box.starter.oauth.common.annotation.Role;
import top.ucat.x.system.entity.SysUser;
import top.ucat.x.system.entity.SysUserRole;
import top.ucat.x.system.service.management.SysUserRoleService;
import top.ucat.x.system.service.management.SysUserService;

import java.util.List;


/**
 * @Auther: Jun
 * @Date: 2019/6/3 18:01
 * @Description:
 */
@RestController
@RequestMapping("sys/user")
@Role("admin")
@AutoPermission("sysUser")
public class SysUserController extends AbstractBaseController<SysUser, SysUserService> {

    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private SysUserRoleService sysUserRoleService;

    @GetMapping("roles")
    public Result getUserRoles(String userId) {
        List<SysUserRole> userRoles = sysUserRoleService.getUserRoles(userId);
        return SystemResult.OK.getResult(userRoles);
    }

    @PostMapping("roles")
    public Result saveUserRoles(@RequestBody List<SysUserRole> userRoles) {
        sysUserRoleService.saveUserRole(userRoles);
        return SystemResult.OK.getResult();
    }

}
